import math

class Solution:
    def getPermutation(self, n: int, k: int) -> str:
        # n_list = list(range(1, n+1))
        n_list = [i for i in range(1, n+1)]
        return self.find_num(n_list, k)

    def find_num(self, n_list: list, k: int):
        length = len(n_list)
        if length == 1:
            return str(n_list[0])
        num = (k - 1) // math.factorial(length - 1)
        res = n_list.pop(num)
        k = k % math.factorial(length - 1)
        return str(res) + self.find_num(n_list, k)


a = Solution()
print(a.getPermutation(4, 1))